<template>
  <div>
    <group title="店名">
      <x-input v-model="merchantInfo.bpName" title="店名"  placeholder=""  ></x-input>
    </group>
    <group title="选择分类">
      <selector v-model="merchantInfo.categoryNo" title="分类" :options="plainList" @on-change="onChange"></selector>
    </group>
    <group title="填写您的联系方式">
      <x-input title="联系电话" name="mobile" v-model="merchantInfo.contactNumber" placeholder="请输入联系电话" keyboard="number" is-type="china-mobile"></x-input>
    </group>
    </group>
    <br>

<group>
      <x-address title="二级省市" v-model="value3" raw-value :list="addressData"></x-address>
    </group>

<group title="地址">
      <x-input title="地址" name="mobile" placeholder="" keyboard="number" v-model="merchantInfo.address"></x-input>
    </group>
<group title="店铺介绍">
      <x-textarea v-model="merchantInfo.note" :max="20" placeholder="请填写详细信息" @on-focus="onEvent('focus')" @on-blur="onEvent('blur')"></x-textarea>
      <x-button @click.native="compelet('go')" type="default">保存</x-button>

    </group>
<toast v-model="showPositionValue" type="text" :time="800" is-show-mask text="保存数据保存成功，页面正在跳转请稍后" :position="position">sdfsdfsdf</toast>
  </div>
</template>

<script>
import { XInput, Group, XButton, Cell,Selector , Picker, GroupTitle , XTextarea, XAddress, ChinaAddressV3Data, Toast} from 'vux'
import store from './mystore.js'
export default {
  components: {
    XInput,
    XButton,
    Group,
    Cell,
    Selector,
    Picker,
    GroupTitle,
 Toast,
XTextarea,
XAddress, ChinaAddressV3Data
  },
  data () {
    return {

        "merchantInfo":{},
      // postData: {
      //   "merchantInfo":{"bpName":"ww","categoryNo":"11","address":"1","contactNumber":"1","note":"1","businessHours":"1"},
      //   "sessionId":"97f72fb8-d600-4d13-a1b2-9e25cd3ee6c2",
      //  "imageModels":[{"imageUrl":"","imageState":"normal"}]
      // },
      years001: [],
       plainList: ['art', 'foods'],
 value3: ['广东省', '中山市', '--'],
addressData: ChinaAddressV3Data,
      value1: 'foods',
      password: '123465',
      password2: '',
      valid1: false,
      valid2: false,
      iconType: '',
      sid:'',
      be2333: function (value) {
        return {
          valid: value === '2333',
          msg: 'Must be 2333'
        }
      },
      style: '',
      disabledValue: 'hello',
      debounceValue: '',
      maxValue: '',
      year001: [],

      position: 'default',
      showPositionValue: false
    }
  },
  computed: {
    sid (){
      return localStorage.getItem('sessionId')
    }
  },
  beforeCreate (){
// let xx = localStorage.getItem('sessionId')

var thissid = localStorage.getItem('sessionId')
console.error(thissid);
this.$http.post(store.getMerchantInfo.url,{},{ headers:{merchantSessionId: thissid} }).then(res => { console.info(res);
	    if(res.body.returnCode==0)  {console.log(1111111,"success")

  console.info(res.body.returnValue,"merchant");

    this.merchantInfo = res.body.returnValue.merchantInfo
      }
    }).then(err =>{ console.error(err,"err");})
  },
  methods: {

    showPosition (position) {
      this.position = position
      this.showPositionValue = true
    },
      compelet (position){

var thissid = localStorage.getItem('sessionId')
let xxd = {"merchantInfo":this.merchantInfo }
console.info(JSON.stringify(this.merchantInfo),"hhhhhhhhhhhh:");
// xxd.push(this.merchantInfo)
        this.$http.post(store.completinfo.url,this.merchantInfo,{ headers:{"merchantSessionId": thissid} }).then( res=>  { console.info(res,"competeting");
        if(res.body.returnCode == 0)
              console.info('hey you successfull jumping to next route');
          {

    // this.merchantInfo = res.body.returnValue.merchantInfo
            console.info("not routing");

      this.position = position
            var _this = this;
      this.showPositionValue = true
            setTimeout(function () {
            _this.$router.push('/sendcards')
              console.error("gogogogogogo");
            }, 2000);
          }
        }).then( err => { console.error(err,"errcomplete!");});
      },
      onEvent (event) {
        console.log('on', event)
      },
    onChange (val) {
    console.info(val);},
    // changeValue (value) {
    //   this.years001 = value
    // },
    getValid1 () {
      this.valid1 = this.$refs.input01.valid
    },
    getValid2 () {
      this.valid2 = this.$refs.input02.valid
    },
    change (val) {
      console.log(val)
    },
    onBlur (val) {
      console.log('on blur', val)
    },
    onFocus (val) {
      console.log('on focus', val)
    }
  }
}
</script>
<style scoped>
.red {
  color: red;
}
.green {
  color: green;
}
</style>
